import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:thinking/entity/_.dart';
import 'package:thinking/widget/_.dart';
import 'package:thinking/config/_.dart';
import 'package:thinking/utils/_.dart';

class Topic extends StatelessWidget{

  final List<Tag> topicList;
  final String title;
  final Function clickTopicItem;
  final bool showMore;

  Topic({required this.topicList,required this.title,required this.clickTopicItem,this.showMore:false});




  @override
  Widget build(BuildContext context) {
    return Panel(
        top: 10,
        bottom: 10,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [Expanded(flex: 1, child: Text(title,style: TextStyle(fontSize: 17,fontWeight:FontWeight.w600 ),),),
                showMore?GestureDetector(
                  onTap: (){},
                  child: Row(
                    children: [
                      GestureDetector(
                        onTap: (){
                          Modular.to.pushNamed('/topicClass');
                        },
                        child: Text(
                          "查看更多",
                          style: TextStyle(color: ColorConfig.TextColor,fontSize: 12),
                        ),
                      ),
                      Icon(
                        Icons.arrow_forward_ios,
                        size: 10,
                        color: ColorConfig.TextColor,
                      )
                    ],
                  ),
                ):Container(),],
            ),
            Container(
              margin: EdgeInsets.only(top: 10),
              height: Screen.setHeight(100),
              child: GridView.builder(
                shrinkWrap: true,
                physics: BouncingScrollPhysics(),
                scrollDirection: Axis.horizontal,
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 2,
                  childAspectRatio: 0.5
                ),
                itemBuilder: (context,index){
                  return GestureDetector(
                    onTap: (){
                      clickTopicItem(topicList[index].id,topicList[index].tagTitle,topicList[index].isSub == true?1:0);
                    },
                    child:Row(
                        children: [
                          Text('#'),
                          SizedBox(width: 6,),
                          Container(
                            width:Screen.setWidth(60) ,
                            child: Text(topicList[index].tagTitle!,overflow: TextOverflow.ellipsis,),
                          ),
                          SizedBox(width: 4,),
                          Container(
                            height: 12,
                            width: 12,
                            decoration: BoxDecoration(
                              color: Config.hotText[topicList[index].tagStatus!]['color'],
                              borderRadius: BorderRadius.all(Radius.circular(2))
                            ),
                            child: Center(
                              child: Text(Config.hotText[topicList[index].tagStatus!]['val'],style: TextStyle(color: Colors.white,fontSize:9),),
                            ),
                          )
                        ],
                      ),
                  );
                },
                itemCount: topicList.length,
              ),
            )
          ],
    ));
  }

}

